package com.bee.study.api;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2019-8-9
 */
@Service
public class ApiFactory {

    // 记得必须加入@Autowired注解注入进来，否则不能遍历
    @Autowired
    public List<ApiInterface> apiInterface;

    public ApiInterface findByName(String name){
        System.out.println("调用工厂!" );
        for (ApiInterface anInterface : apiInterface) {
            System.out.println("调用工厂支持的类型:" + anInterface.type());
            if (StringUtils.equals(anInterface.type(), name)) {
                return anInterface;
            }
        }
        return null;
    }
}
